Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply 'react-native-safe-area-context' to support Android 15 forced edge-to-edge #84

Conversation

alanleedev
Copy link
Collaborator

@alanleedev alanleedev commented Nov 19, 2024

Summary:

Why:

<SafeAreaView/> is iOS only. This becomes an issue for Android 15, where edge-to-edge is mandatory. We should be guiding users how to write good apps to handle this.

How:

This change updates the template to show our current recommended pattern for writing apps that are aware of the safe area to layout components.

Changes:

  • Added react-native-safe-area-context to handle forced ege-to-edge on Android 15

  • Updating Android targetSdk to 35

  • Very important note: This PR requires updated to the Header component (PR here) under the Libraries/NewAppScreen for it to work, which will have to go out in a release. This change can't land in a -stable branch until that commit is picked for a branch.

Changelog:

[GENERAL] [ADDED] - Added react-native-safe-area-context to handle forced ege-to-edge on Android 15
[ANDROID] [CHANGED] - Updating Android TargetSdk to 35

Test Plan:

Applied same code to new app created with template, and have captured screenshots:

A B
ios_template_updated.mp4
android_template_updated_api35_3button.mp4
android_template_updated_api35_gesture.mp4
android_template_updated_api34.mp4

@alanleedev alanleedev self-assigned this Nov 19, 2024
backgroundColor={backgroundStyle.backgroundColor}
/>
<ScrollView
contentInsetAdjustmentBehavior="automatic"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace iOS only contentInsetAdjustmentBehavior with code that can work on both iOS and Android

@blakef
Copy link
Collaborator

blakef commented Nov 19, 2024

CC: @cipolleschi, we should discuss offline with @alanleedev. There's possibly a way to put this together where the diff on the upgrade helper will be less noisy.

};

const contentContainerStyle = { paddingBottom: insets.bottom };
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to add extra padding so when scrolling to the bottom, the content shows above the nav bar without overlap.

<ScrollView
contentContainerStyle={contentContainerStyle}
style={backgroundStyle}>
<Header badgeTopMargin={insets.top}/>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

passing in badgeTopMargin to the HermesBadge within Header has proper margin to avoid overlap with top status bar.

Pre-requisite: This code requires updated to react-native with this PR applied: facebook/react-native#47708

@cipolleschi
Copy link
Contributor

I don't believe that forcing the react-native-safe-area-context library on every project is the right thing to do.
If we push that here, everyone that will update from 0.76 to 0.77 will see these changes, including people that are upgrading a project that is using a different library then safe-area-context.

We don't want to establish a precedent for libraries to be included in the official template, as we would like not to be opinionated on the libraries that people should use.

I'd really really prefer if we can find an alternative way to handle that that does not require that library to be pushed in all the projects.

Comment on lines +59 to +64
return (
<SafeAreaProvider>
<MainContent />
</SafeAreaProvider>
);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the reason for this, but this will show a huge braking change block in users code that is not really required. Can't we just replace the <SafeAreaView> with <SafeArewProvider>?

@alanleedev
Copy link
Collaborator Author

alanleedev commented Nov 19, 2024

We don't want to establish a precedent for libraries to be included in the official template, as we would like not to be opinionated on the libraries that people should use.

@cipolleschi I think we are already made an opinionated anouncement about the library people use in this case. Made an announcement recommending react-native-safe-area-context here -> react-native-community/discussions-and-proposals#827

@alanleedev
Copy link
Collaborator Author

Closing in favor of different approach to handle the issue: #85

@alanleedev alanleedev closed this Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants